package com.example.listviewtest;

import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import java.util.List;

public class ListAdapter extends ArrayAdapter<PC> {
    private int resourceId;
    public ListAdapter(Context context, int textViewResourceId, List<PC> objects){
        super(context,textViewResourceId,objects);
        resourceId=textViewResourceId;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent){
        PC pc=getItem(position);
        View view= LayoutInflater.from(getContext()).inflate(resourceId,parent,false);
        TextView id=(TextView) view.findViewById(R.id.id);
        TextView name=(TextView) view.findViewById(R.id.name);
        TextView count=(TextView) view.findViewById(R.id.count);
        if (position==0) id.setBackgroundResource(R.drawable.id_text_background);
        if (position==1) id.setBackgroundResource(R.drawable.id_23_background);
        if (position==2) id.setBackgroundResource(R.drawable.id_2_background);
        id.setText(pc.getId());
        name.setText(pc.getName());
        count.setText(pc.getCount());
        return view;
    }
}